// import { useStorage } from '@vueuse/core'

export const state = reactive({
  data: `{
    "tableComment": "用户表",
    "tableName": "sys_user",
    "columns": [
      {
        "columnComment": "主键",
        "columnName": "id",
        "columnType": "varchar(64)",
        "isPrimary": true,
        "isAutoIncrement": false,
        "isNonNull": true,
        "columnDefault": null
      },
      {
        "columnComment": "账号",
        "columnName": "username",
        "columnType": "varchar(64)",
        "isPrimary": false,
        "isAutoIncrement": false,
        "isNonNull": true,
        "columnDefault": null
      },
      {
        "columnComment": "密码",
        "columnName": "password",
        "columnType": "varchar(256)",
        "isPrimary": false,
        "isAutoIncrement": false,
        "isNonNull": true,
        "columnDefault": null
      },
      {
        "columnComment": "姓名",
        "columnName": "name",
        "columnType": "varchar(64)",
        "isPrimary": false,
        "isAutoIncrement": false,
        "isNonNull": false,
        "columnDefault": null
      },
      {
        "columnComment": "手机号",
        "columnName": "phone",
        "columnType": "varchar(64)",
        "isPrimary": null,
        "isAutoIncrement": false,
        "isNonNull": false,
        "columnDefault": null
      },
      {
        "columnComment": "邮箱",
        "columnName": "email",
        "columnType": "varchar(64)",
        "isPrimary": null,
        "isAutoIncrement": false,
        "isNonNull": false,
        "columnDefault": null
      },
      {
        "columnComment": "登录错误次数",
        "columnName": "err_count",
        "columnType": "int",
        "isPrimary": false,
        "isAutoIncrement": false,
        "isNonNull": false,
        "columnDefault": null
      },
      {
        "columnComment": "身价资产(元)",
        "columnName": "personal_value",
        "columnType": "decimal(18,2)",
        "isPrimary": false,
        "isAutoIncrement": false,
        "isNonNull": false,
        "columnDefault": null
      },
      {
        "columnComment": "状态(0-正常 1-停用)",
        "columnName": "status",
        "columnType": "varchar(1)",
        "isPrimary": false,
        "isAutoIncrement": false,
        "isNonNull": true,
        "columnDefault": "'0'"
      },
      {
        "columnComment": "创建人",
        "columnName": "create_by",
        "columnType": "varchar(64)",
        "isPrimary": false,
        "isAutoIncrement": false,
        "isNonNull": false,
        "columnDefault": null
      },
      {
        "columnComment": "创建时间",
        "columnName": "create_at",
        "columnType": "timestamp",
        "isPrimary": false,
        "isAutoIncrement": false,
        "isNonNull": false,
        "columnDefault": null
      },
      {
        "columnComment": "修改人",
        "columnName": "update_by",
        "columnType": "varchar(64)",
        "isPrimary": false,
        "isAutoIncrement": false,
        "isNonNull": false,
        "columnDefault": null
      },
      {
        "columnComment": "修改时间",
        "columnName": "update_at",
        "columnType": "timestamp",
        "isPrimary": false,
        "isAutoIncrement": false,
        "isNonNull": false,
        "columnDefault": null
      },
      {
        "columnComment": "删除标志(0-未删除 1-已删除)",
        "columnName": "delete_flag",
        "columnType": "varchar(1)",
        "isPrimary": false,
        "isAutoIncrement": false,
        "isNonNull": true,
        "columnDefault": "'0'"
      }
    ]
  }`.trim(),
  tmpl: `
  import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fofund.ark.common.annotation.Keyword;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import java.util.List;
<%
/* 通用字段的特殊处理 */
const modelName = pascal(tableName.split('_')[1])  // 去掉sys_前缀
const createColumns = ['create_by','create_at']
const updateColumns = ['update_by','update_at'] 
const deleteFlag = 'delete_flag'
%>
/**
 * {{_.trimEnd(tableComment, '表')}}
 *
 * @author 何鹏举 {{dayjs().format('YYYY-MM-DD')}}
 */
@Data
@TableName("{{tableName}}") @Schema(description = "{{_.trimEnd(tableComment, '表')}}")
public class {{modelName}} {
   {{each columns c}}
    @Schema(description = "{{c.columnComment}}"){{if c.isPrimary}}
    @TableId(type = IdType.ASSIGN_ID){{/if}}{{if createColumns.indexOf(_.toLower(c.columnName)) > 0}}
    @TableField(fill = FieldFill.INSERT, updateStrategy = FieldStrategy.NEVER){{/if}}{{if updateColumns.indexOf(_.toLower(c.columnName)) > 0}}
    @TableField(fill = FieldFill.UPDATE, insertStrategy = FieldStrategy.NEVER){{/if}}{{if deleteFlag === c.columnName}}
    @TableLogic  @JsonIgnore{{/if}}
    private {{typeMapping(c.columnType, 'java')}} {{camel(c.columnName)}};
   {{/each}}
}
  `.trim()
})